

**first import the 2016 dataset 
import delimited "/datasets/MPDataset_MPDS2016b_est2.csv", varnames(1) encoding(ISO-8859-1) clear
gen lr_tavits=(per401+per402+per407+per409+per410+per505+per507+per4011+per4012+per4013)- ///
(per403+per404+per406+per412+per413+per503+per504+per506+per4123+per4124+per4131+per4132)

format %24s partyname

keep countryname edate party partyname partyab lr_tavits absseat totseats

keep if countryname=="Poland"|countryname=="Hungary"

keep if edate=="08/05/1994"|edate=="10/05/1998"|edate=="19/09/1993"|edate=="21/09/1997"

**gen a variable with number of seats for each of the four coalitions

gen left_member=0
replace left_member=1 if partyabb=="MSzP"|partyabb=="SzDSz"|partyabb=="SLD"|partyabb=="PSL"

gen right_member=0
replace right_member=1 if partyabb=="FiDeSz"|partyabb=="MDF"|partyabb=="FKgP"| ///
		partyabb=="FiDeSz-MPP"|partyabb=="FiDeSz-MPP-MDF"|partyabb=="MDF"|partyabb=="MDF-FiDeSz-MPP"| ///
		partyabb=="AWS"|partyabb=="UW"|partyabb=="BBWR"|partyabb=="UD"

		**on the 1998 right coalition in hungary: according to wikipedia fidesz got 148, mdf 17, and fkgp 48
		*in the CMP data Fidesz-mpp has 113+ fidesz-mpp-mdf 35=148. These two coalitions have the same score, same manifesto
			*also MDF has 2 seats, and MDF-fidesz-mpp has 15 seats= 17 together, these two coalitions have same score
			* finally fkgp has 48
			*OVERALL IT ALL ADDS UP PERFECTLY
		
by edate, sort: egen tot_seat_left=total(absseat) if left_member==1
by edate, sort: egen tot_seat_right=total(absseat) if right_member==1

gen left_prop=absseat/tot_seat_left
gen right_prop=absseat/tot_seat_right

gen left_prov=lr_tavits*left_prop
gen right_prov=lr_tavits*right_prop

by edate, sort: egen left_final=total(left_prov)
by edate, sort: egen right_final=total(right_prov)

***now create average for each parliament
by edate, sort: egen tot_seats2=total(absseat)
gen proportion=absseat/tot_seats2
gen parl_id_prov=lr_tavits*proportion
by edate, sort: egen parliament_final=total(parl_id_prov)

keep country edate left_final right_final parliament_final

drop if edate==edate[_n-1]


save "figures/coalitions_H_P.dta", replace






